import json
import os
from feature_set.app.un.app_un_rule_v1.AppUnRuleV1 import AppUnRuleV1
from feature_set.app.un.app_un_rule_v1.minhash_redis import MinHashRedis
class AppIdRuleV1(AppUnRuleV1):
    def __init__(self):
        super().__init__()
        self.root_dir = self.get_root_dir(os.path.abspath("."))
        self.conf_dir = os.path.join(self.root_dir, "feature_conf")
        
        self.country_info = json.load(
            open(
                os.path.join(
                    self.conf_dir,
                    "app",
                    "id",
                    "app_id_rule_v1",
                    "app_id_rule_v1_country_info.json",
                )
            )
        )
        self.package_conf = {'whatsapp': 'com.whatsapp'}
        self.feature_dict = {
            'app_cnt': 'float',
            'pre_inst_cnt': 'float',
            'non_pre_inst_cnt': 'float',
            'whatsapp_install': 'float',
            'auto_generated_install': 'float',
            'lineageos_overlay_customization_install': 'float',
            'fingerprint_identical_user_cnt': 'float',
            'fingerprint_top1_similarity': 'float',
            'fingerprint_top2_similarity': 'float',
            'fingerprint_top3_similarity': 'float',
            'fingerprint_similar_user_cnt_70': 'float',
            'fingerprint_similar_user_cnt_80': 'float',
            'fingerprint_similar_user_cnt_90': 'float',
            'fingerprint_similar_user_cnt_95': 'float',
            'fingerprint_similar_user_cnt_97': 'float',
            'fingerprint_similar_user_cnt_99': 'float',
            'fingerprint_top1_sim_uid': 'str',
            'fingerprint_top2_sim_uid': 'str',
            'fingerprint_top3_sim_uid': 'str'
            }
        
        self.minhash_redis_host = self.country_info['minhash_redis_host']
        self.minhash_redis_port = self.country_info['minhash_redis_port']
        self.minhash_redis_db = self.country_info['minhash_redis_db']
        self.minhash_redis_password = self.country_info['minhash_redis_password']
        self.minhash_basename =  self.country_info['minhash_basename']
        
        self.minhash_config = {
            'redis_host': self.minhash_redis_host,
            'redis_port': self.minhash_redis_port,
            'redis_db': self.minhash_redis_db,
            'basename': self.minhash_basename,
            'password': self.minhash_redis_password,
            'num_perm': 64,
            'threshold': 0.5,
            'expire_time': 86400 * 7
        }
        
        self.minhash_redis = MinHashRedis(**self.minhash_config)
